/**
 * -----------------------------------
 * Copyright (c) 2021-2025
 * All rights reserved, Designed By www.linfengtech.cn
 * 林风社交论坛商业版本请务必保留此注释头信息
 * 商业版授权联系技术客服	 QQ:  3582996245
 * 严禁分享、盗用、转卖源码或非法牟利！
 * 版权所有 ，侵权必究！
 * -----------------------------------
 */
package io.linfeng.modules.app.controller;

import io.linfeng.common.annotation.NoRepeatSubmit;
import io.linfeng.common.utils.Result;
import io.linfeng.common.vo.OrderPay;
import io.linfeng.common.utils.Constant;
import io.linfeng.common.utils.R;
import io.linfeng.modules.admin.entity.AppUserEntity;
import io.linfeng.modules.admin.entity.VipOptionEntity;
import io.linfeng.modules.admin.service.VipOptionService;
import io.linfeng.modules.app.annotation.Login;
import io.linfeng.modules.app.annotation.LoginUser;
import io.linfeng.modules.app.param.VipPayForm;
import io.linfeng.modules.app.param.VipRechargeForm;
import io.linfeng.modules.sys.service.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 会员充值选项
 *
 * @author JL.Yu
 * @email linfengtech001@163.com
 * @date 2022-09-28 14:26:17
 */
@RestController
@RequestMapping("app/vip")
@Api(tags = "移动端——会员充值选项")
public class AppVipOptionController {

    @Autowired
    private VipOptionService vipOptionService;

    @Autowired
    private SysConfigService configService;


    @GetMapping("/vipList")
    @ApiOperation("会员充值选项列表")
    public Result<List<VipOptionEntity>> vipList(){
        List<VipOptionEntity> result = vipOptionService.lambdaQuery()
                .orderByAsc(VipOptionEntity::getSort)
                .list();
        return new Result<List<VipOptionEntity>>().ok(result);
    }


    @GetMapping("/vipConfig")
    @ApiOperation("会员配置查询")
    public R vipConfig(){
        return R.ok()
                .put("integralNum", configService.getValue(Constant.VIP_INTEGRAL))
                .put("renameCount",configService.getValue(Constant.VIP_RENAME))
                .put("topicNum",configService.getValue(Constant.VIP_TOPIC_NUMBER));
    }


    @Login
    @PostMapping("/rechargeVip")
    @ApiOperation("会员预充值")
    public R rechargeVip(@ApiIgnore @LoginUser AppUserEntity user, @RequestBody VipRechargeForm param){

        String orderId = vipOptionService.rechargeVip(user,param);
        return R.ok().put("result",orderId);
    }


    @Login
    @PostMapping("/rechargeVipByYue")
    @ApiOperation("会员余额支付")
    @NoRepeatSubmit
    public R rechargeVipByYue(@ApiIgnore @LoginUser AppUserEntity user,
                              @RequestBody VipRechargeForm param){

        vipOptionService.rechargeVipByYue(user.getUid(),param);
        return R.ok();
    }

    @Login
    @PostMapping("/pay")
    @ApiOperation("会员充值微信支付")
    public R pay(@ApiIgnore @LoginUser AppUserEntity user, @RequestBody VipPayForm param, HttpServletRequest request) throws Exception{

        OrderPay orderPay=vipOptionService.vipPay(user,param,request);
        return R.ok().put("data",orderPay);
    }

}
